<%@page import="org.apache.shiro.SecurityUtils"%>
<%@page import="org.apache.shiro.subject.Subject"%>
<%@page import="org.apache.shiro.web.util.WebUtils"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%
    Subject subject = SecurityUtils.getSubject();
    boolean hasRemembered=false;
    if(subject!=null && (subject.isRemembered() || subject.isAuthenticated())){
        hasRemembered=true;
    }
    if(WebUtils.getSavedRequest(request)!=null){
    	String requestUrl=WebUtils.getSavedRequest(request).getRequestUrl();
    	request.setAttribute("requestUrl", requestUrl);
    }
    
%>
<html>
<head>
<title>易联工单系统</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/WEB-INF/pages/common/includeCoreCssJs.jsp"%>
<link href="${root}/res/css/ieUpdate.css" rel="stylesheet" type="text/css" />
<link href="${root}/res/css/index/form-elements.css" rel="stylesheet" type="text/css" />
<link href="${root}/res/css/index/style.css" rel="stylesheet" type="text/css" />
<style>
</style>
</head>
<body>
	<!-- 代码 开始 -->
<div style="display: none" id=browser_ie>
    <div class=brower_info>
        <div class=notice_info>
            <p>你的浏览器版本过低，可能导致网站不能正常访问！<br>为了你能正常使用网站功能，请使用这些浏览器。</p></div>
            <div class=browser_list>
            <span>
            <a href="https://www.baidu.com/s?ie=UTF-8&wd=chrome" target=_blank>
            <img src="${root}/res/images/Chrome.png"><br>chrome
            </a>
            </span>
            <span><a href="https://www.baidu.com/s?ie=UTF-8&wd=firefox" target=_blank><img
            src="${root}/res/images/Firefox.png"><br>firefox
            </a></span>
            <span><a href="https://www.baidu.com/s?ie=UTF-8&wd=safari" target=_blank><img
            src="${root}/res/images/Safari.png"><br>safari
            </a></span>
            <span><a
            href="https://www.baidu.com/s?ie=UTF-8&wd=ie9"
            target=_blank><img
            src="${root}/res/images/IE.png"><br>ie9及以上
            </a></span>
            </div>
    </div>
</div>
	<!-- Top content -->
	<div class="top-content">

		<div class="inner-bg">
			<div class="container">
				<div class="row">
					<div class="col-sm-8 col-sm-offset-2 text">
						<h1>
							<strong><span style="color: #0099FF;font-weight: bold;">易联</span></strong>工单系统
						</h1>
						<div class="description">
							<p>
								工单管理、知识库、通知公告、留言板、考试
							</p>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-sm-6 col-sm-offset-3 form-box">
						<div class="form-top">
							<div class="form-top-left">
								<h3>登录框</h3>
								<p>请输入用户名及密码:</p>
							</div>
							<div class="form-top-right">
								<i class="fa fa-lock"></i>
							</div>
						</div>
						<div class="form-bottom">
							<div id="loginForm" role="form" class="login-form" method="post">
								<input type=hidden id="ssid" name="ssid" value="<%=request.getSession().getId()%>">
								<div class="form-group">
									<label class="sr-only" for="loginName">用户名</label>
									<input type="text" name="loginName" placeholder="用户名..." class="form-username form-control" check-type="required">
								</div>
								<div class="form-group">
									<label class="sr-only" for="password">密码</label>
									<input type="password" name="password" placeholder="密码..." class="form-password form-control" check-type="required" >
								</div>
								<div class="form-group">
									<label class="sr-only" for="password">验证码</label>
									<img src="${ctx}/captcha-image.jpg" id="captchaImage" title="看不清,点击换一张" style="float: right;"/>
									<input type="text" name="captcha" placeholder="验证码..." class="form-username form-control" check-type="required" style="width: 50%;float:left;">
									<div style="clear: both;"></div>
								</div>
								
								<button type="button" class="btn" id="loginBt">登&nbsp;&nbsp;录</button>
								<!-- 
								<div class="checkbox">
					        		<label>
					        			<input id="remember-me" name="canRememberMe" value="true" type="checkbox">
					        			记住密码
					                </label>
					        	</div>
					        	 -->
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<%@ include file="/WEB-INF/pages/common/includeUiScript.jsp"%>
	<script src="${root}/res/jsLib/jquery.backstretch.min.js"></script>
	<script type="text/javascript">
	$(function(){
		var form;
		var requestUrl='${requestUrl}';
		if(top.wiseMen.platform.mainPage){
			top.window.location.href=root+"/Index.jsp"; 
		}
		
		if (!$.support.leadingWhitespace) {
			$("#browser_ie").show();
		}
		
		$.backstretch("${root}/res/images/index/1.jpg");
		$("#captchaImage").click(function(){
			$(this).attr("src",'${ctx}/captcha-image.jpg?_t='+new Date().getTime());
		});
		
	    var hasRemembered=false;
	    
    	if(!(typeof sysReLogin=='undefined')){
    		sysReLogin.call(null);
    	}
    	
    	form=$('#loginForm');
    	form.validation({reqmark:false});

        $("#loginBt").click(function () {
            login();
        });
        form.find("input[name=password],input[name=captcha]").keydown(function(e){
        	if(e.keyCode==13){
        		login();
        	}
        });
        var loginName = $.cookie('loginName');
        var canRememberMe=$.cookie('canRememberMe');
        if (loginName) {
        	form.find("input[name=loginName]").val(loginName);
            if((canRememberMe==true || canRememberMe=="true") && hasRemembered=="true"){
            	form.find("input[name=canRememberMe]").attr("checked", true);
                window.location.href="${ctx }/user/remLogin";
            }
        }
        
        function login(){
        	var loginName = form.find("input[name=loginName]").val();
            var canRememberMe=form.find("input[name=canRememberMe]").val();
            
            if (isValid()) {
                $.cookie('loginName', loginName, {expires: 7,path : '/'});
                $.cookie('canRememberMe', canRememberMe, {expires: 7,path : '/'});
                var datas=webUtils.formToObj($("#loginForm"));
                var postDataStr=JSON.stringify(datas);
				var postDataStrBase64=Base64.encode(postDataStr);
				$.post(ctx + '/jsonLogin.do',{
					code:postDataStrBase64
				},function(data){
					if (data.state==1) {
						if(requestUrl && requestUrl!=ctx){
							window.location.href=requestUrl;
						}else{
							window.location.href=ctx+"/main.do"
						}
                    }else if (data.state==4) {
                        window.location.href=ctx+"/toSelectOrg.do"
                    } else {
                    	webUtils.error(data.desc);
                    	form.find("input[name=password]").val("");
                    	form.find("input[name=captcha]").val("");
                    	$("#captchaImage").click();
                    }
				},"json");
            }else{
            }
        }
        
        function isValid(){
        	return form.valid();
        }
	});
	</script>
</body>
</html>

